/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;

/**
 *
 * @author eli
 */
public class FabricaConexao
{
    private Connection con;
    
    public Connection fazConexao()
    {
        try
        {
            if( this.con == null )
            {
                //Class.forName("org.gjt.mm.mysql.Driver");
                String url = "jdbc:mysql://localhost:3306/bancoswing1";
                this.con = DriverManager.getConnection(url, "root", "server");
                this.con.setAutoCommit(false);
            }
        }
        catch( Exception e ){}
        
        return this.con;
    }
    
    public void commitConexao()
    {
        try
        {
            this.con.commit();
        }
        catch( Exception e ){}
    }
    
    public void rollbackConexao()
    {
        try
        {
            this.con.rollback();
        }
        catch( Exception e ){}
    }
    
    public void fecharConexao()
    {
        // Fechando a conexão
        try
        {
            if( this.con != null )
            {
                this.con.close();
            }
        }
        catch( Exception e ){}
    }
}
